/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet;

import Bean.MeasureData;
import Bean.User;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.VineryManager;


/**
 *
 * @author Vincenzo
 */
public class Controller extends HttpServlet {

    public model.VineryManager vm;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
       vm =(VineryManager) getServletContext().getAttribute("vinery-manager");
        HttpSession session = request.getSession();
       User w=(User)session.getAttribute("worker");
       String work= w.getWork();
       if(work.equals("Agronomous"))
               this.agronomousHandle(request, response);
       else if(work.equals("Oenologist"))
           this.oenologistHandle();
       else if(work.equals("Seller"))
           this.sellerHandle();
       else if(work.equals("Warehouseman"))
           this.warehousemanHandle();
       else if(work.equals("Commercial"))
           this.commercialHandle();
       else if(work.equals("Marketingexpert"))
           this.marketingexpertHandle();
    } 


    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
       this.doGet(request, response);
    }

    private void agronomousHandle(HttpServletRequest request, HttpServletResponse response) {
        String query=request.getParameter("query");
        String value=request.getParameter("parameter");
        int v_id = Integer.parseInt(request.getParameter("id"));
        if(query.equals("monitoring_parameter")){
            if(value.equals("all")){
                
               List<MeasureData> l=vm.monitoringParameter(v_id);
               int size=l.size();
               for(MeasureData m: l)
                   System.out.println(m.getValue());
            }
            else{
                vm.
            }
        }
        else if(query.equals("vineyard_events")){
            if(value.equals("all")){
            
            
            }
            else{

            }
        }

    }

    private void oenologistHandle() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void sellerHandle() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void warehousemanHandle() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void commercialHandle() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void marketingexpertHandle() {
        throw new UnsupportedOperationException("Not yet implemented");
    }


}
